# -*- coding: utf-8 -*-
# @Time    : 2024/12/9  15:49
# @Author  : Nabby
# @FileName: jasco_declaration_information_impl.py
# @Desc    : 申报信息
from app import db
from infrastructure.po.mode.jasco_file_manage import (
    JascoFileManage,
)
from sqlalchemy import and_, or_, desc, asc


class JascoFileManageImpl(object):

    @classmethod
    def get_file_manage_list(cls, order_id, page=1, page_size=999):
        query = db.session.query(JascoFileManage).filter(
            JascoFileManage.order_id == order_id
        )
        return (
            query.order_by(JascoFileManage.create_time.desc()).paginate(
                page=page, per_page=page_size
            ),
            query.count(),
        )

    @classmethod
    def add_file(
        cls,
        order_id,
        type,
        file_name,
        source,
        remark,
        file_path,
            etd,
            pol,
            company_name,
            linkman,
            phone,
            email,
            invoice_number,
            goods_name,
            loading_time,
            total_packages,
            total_weight,
            total_volume,
            atd,
            actual_pol,
            eta,
            pod,
            vel,
            mbl,
            hbl,
            deliver_to,
            terms
    ):

        jasco_file = JascoFileManage(
            order_id=order_id,
            type=type,
            file_name=file_name,
            source=source,
            remark=remark,
            file_path=file_path,
            etd=etd,
            pol=pol,
            company_name=company_name,
            linkman=linkman,
            phone=phone,
            email=email,
            invoice_number=invoice_number,
            goods_name=goods_name,
            loading_time=loading_time,
            total_packages=total_packages,
            total_weight=total_weight,
            total_volume=total_volume,
            atd=atd,
            actual_pol=actual_pol,
            eta=eta,
            pod=pod,
            vel=vel,
            mbl=mbl,
            hbl=hbl,
            deliver_to=deliver_to,
            terms=terms

        )
        db.session.add(jasco_file)
        db.session.flush()
        db.session.commit()
        return True

# @classmethod
# def delete_file(cls, id, order_id):
#     """
#     删除文件
#     :param id:
#     :param order_id:
#     :return:
#     """
#     jasco_file = JascoFileManage.query.filter(
#         JascoFileManage.id == id,
#         JascoFileManage.order_id == order_id
#     ).first()
#     if jasco_file:
#         db.session.delete(jasco_file)
#         db.session.commit()
#         return True
#     return False